package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: TaskToTagServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_task_to_tag
 * Comment:
 * 任务标签映射表
 */
@Service
public class TaskToTagServiceImpl extends TaskToTagServiceCustomImpl implements TaskToTagService {

    static {
        beanClassNameMap.put("task_to_tag", "taskToTagServiceImpl");
        listMethodNameMap.put("task_to_tag", "listTaskToTag");
        listMethodParameterClassNameMap.put("task_to_tag", "TaskToTagQueryRequest");
        updateMethodNameMap.put("task_to_tag", "updateTaskToTag");
        updateMethodParameterClassNameMap.put("task_to_tag", "TaskToTagUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addTaskToTag(TaskToTagAddRequest request) throws Exception {
        super.fixRequest("task_to_tag", "add", request);
        return super.addTaskToTag(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateTaskToTag(TaskToTagUpdateRequest request) throws Exception {
        TaskToTag record = null;
        record = taskToTagMapper.selectByPrimaryKey(request.getId());
        super.fixRequest("task_to_tag", "update", request, record);
        return super.updateTaskToTag(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteTaskToTag(TaskToTagDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<TaskToTag> list = null;
            TaskToTagExample example = new TaskToTagExample();
            example.createCriteria().andIdIn(request.getIdList());
            list = taskToTagMapper.selectByExample(example);
            fixRequest("task_to_tag", "delete", request, list);
        } else {
            fixRequest("task_to_tag", "delete", request);
        }
        return super.deleteTaskToTag(request);
    }

    @Override
    public TaskToTagQueryResponse queryTaskToTag(TaskToTagQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "id");
        TaskToTagQueryResponse result = super.queryTaskToTag(request);
        checkResult("task_to_tag", "query", request, result);
        return result;
    }

    @Override
    public List<TaskToTagQueryResponse> listTaskToTag(TaskToTagQueryRequest request) throws Exception {
        List<TaskToTagQueryResponse> list = super.listTaskToTag(request);
        checkResult("task_to_tag", "list", request, list);
        return list;
    }

    @Override
    public Integer countTaskToTag(TaskToTagQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_to_tag", "count", request);
        return super.countTaskToTag(request);
    }

    @Override
    public BaseStatResponse statTaskToTag(TaskToTagQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task_to_tag", "stat", request);
        return super.statTaskToTag(request);
    }

    @Override
    public TaskToTagForTagsResponse tags(TaskToTagForTagsRequest request) throws Exception {
        super.fixRequest("task_to_tag", "tags", request);
        TaskToTagForTagsResponse result = super.tags(request);
        checkResult("task_to_tag", "tags", request, result);
        return result;
    }

}
